package com.zkingsoft.web.tag;

import java.io.IOException;
import java.io.StringWriter;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import com.matrix.core.tools.LogUtil;
import com.zkingsoft.web.bean.WebAd;
import com.zkingsoft.web.service.WebAdService;
import com.zkingsoft.web.tool.SystemConstance;
import com.zkingsoft.web.tool.WebUtil;

public class AdsTag extends SimpleTagSupport {

	/**
	 * 广告类型
	 */
	private String code;

	/**
	 * 变量名称
	 */
	private String var;
 
	/**
	 * 获取广告
	 * 
	 * @author jiangyouyao
	 */
	public void doTag() throws JspException, IOException {
		WebAdService adService = WebUtil.getService(this.getJspContext(), SystemConstance.AD_SERVICE);
		LogUtil.debug("====>>{}", adService);
		List<WebAd> list = adService.selectAdByCodes(code);
		for (WebAd webAd : list) {
			this.getJspContext().setAttribute(webAd.getCode(), webAd);
		}
	}

	public String getVar() {
		return var;
	}

	public void setVar(String var) {
		this.var = var;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	} 

	StringWriter sw = new StringWriter();

}